
package ipark.gui.mapeditor;

import java.awt.*;
import java.io.Serializable;
import javax.swing.ImageIcon;

/**
 * Camera component
 * @author jernej
 */
public class Camera extends MapComponent  implements Serializable{
    
    private transient Image image = null;
    
    public Camera(){
      super();
      loadImages();
      try {
           MediaTracker tracker = new MediaTracker(this);
           tracker.addImage(image, 0);
           tracker.waitForID(0);
      } catch (Exception e) {}
      setSize(image.getWidth(this),image.getHeight(this));
      setName("Camera");
      setWidthMeters(1);
      setHeightMeters(1);
  }
    public Camera(Camera comp){
      this();
      setLocation(comp.getLocation());
      setSize(comp.getSize());
      setName(comp.getName());
    }

    @Override
    public ImageIcon getIcon(int iWidth, int iHeight) {
        return new ImageIcon(image.getScaledInstance(iWidth,iHeight, Image.SCALE_SMOOTH));
    }

    @Override
    public boolean isHorizontalResizable() {
        return false;
    }

    @Override
    public boolean isVerticalResizable() {
        return false;
    }

    @Override
    public boolean isDiagonalResizable() {
        return false;
    }

    @Override
    public double minHeightMeters() {
        return 1;
    }

    @Override
    public double minWidthMeters() {
        return 1;
    }

    @Override
    public String[] getPropertyNames() {
        String[] ret = {"Name"};
        return ret;
    }

    @Override
    public Object getPropertyValue(String name) {
      if(name.equals("Name"))
          return getName();
      return null;
    }

    @Override
    public boolean setPropertyValue(String name, String value) {
      if(name.equals("Name")){
          setName(value);
          return true;
      }
      return false;
    }
    
    @Override
    public void paint(Graphics g){
        super.paint(g);
        //izrišemo sliko, ki predstavlja ta objekt
        g.drawImage(image, getLocation().x, getLocation().y,getLocation().x+getWidth(),
                    getLocation().y+getHeight(), 0, 0, image.getWidth(this), image.getHeight(this), this);
    }

    @Override
    public String[] getTypeNames(String property) {
        return null;
    }
    
    @Override
    public MapComponent duplicate() {
        MapComponent ret = new Camera(this);
        return ret;
    }

    @Override
    public boolean jointSide(int side) {
        return false;
    }

    @Override
    public void loadImages() {
        if(image == null)
            image = Toolkit.getDefaultToolkit().getImage(MapComponent.class.getResource("resources/camera.png"));
    }

}
